package cn.swing.his.log.webapi.controller;

import cn.swing.his.common.web.JsonPage;
import cn.swing.his.common.web.JsonResult;
import cn.swing.his.log.service.ILogService;
import cn.swing.his.pojo.log.vo.LogTempVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping(value = "/log", produces = "application/json;charset=utf-8")
@Api(tags="日志模块")
public class LogController {
    @Autowired
    ILogService logService;

    /**********************************  insert   *********************************/

    /**********************************  delete   *********************************/

    @ApiOperation("删除日志")
    @GetMapping("/delete-log")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "日志id", name = "id", example = "1"),
    })
    public JsonResult<Integer> deleteLogById(Integer id) {
        return JsonResult.ok("删除成功",logService.deleteLogById(id));
    }


    /**********************************  update   *********************************/

    /**********************************  select   *********************************/
    @ApiOperation("查询日志列表")
    @PostMapping("/get-log-list")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum", example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "10"),
    })
    public JsonResult<JsonPage<LogTempVO>> getLogList(Integer pageNum, Integer pageSize) {
        JsonPage<LogTempVO> logList = logService.getLogList(pageNum, pageSize);
        return JsonResult.ok("查询成功",logList);
    }

    @ApiOperation("按照时间段查询日志列表")
    @PostMapping("get-log-byTime")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum", example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "10"),
            @ApiImplicitParam(value = "开始时间", name = "startTime", example = "2022-07-21 14:54:43"),
            @ApiImplicitParam(value = "结束时间", name = "endTime", example = "2022-07-21 14:55:11"),
    })
    public JsonResult<JsonPage<LogTempVO>> getLogListByTime(Integer pageNum, Integer pageSize, String startTime, String endTime) {
        JsonPage<LogTempVO> logList = logService.getLogListByTime(pageNum,pageSize,startTime,endTime);
        return JsonResult.ok("查询成功",logList);
    }




}
